package aop;

import java.util.HashMap;
import java.util.Map;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-10 09:03
 * @since JDK 1.6
 */
public class Hello implements IHello {

    @Override
    public void sayHello(String name) {
        System.out.println(name+" say hello");
    }


    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>() {
            {
                put("/c", "/c");
            }
        };

        String target = "/a/b/c/d";
        if(!target.startsWith("/")){
            target = "/" + target;
        }

        Object o = map.get(target);
        String pathParamPart = null;

        while (o == null && target.contains("/")) {
            String tempPath;
            String tempPathParam;
            if (target.lastIndexOf("/") == 0) {
                tempPath = "/";
            } else {
                tempPath = target.substring(0, target.lastIndexOf("/"));
            }
            tempPathParam = target.substring(target.lastIndexOf("/")+1);

            o = map.get(tempPath);
            target = tempPath;
            if (pathParamPart == null) {
                pathParamPart = tempPathParam;
            } else {
                pathParamPart = tempPathParam + "/" + pathParamPart;
            }

            if (target.equals("/")) {
                break;
            }

            System.out.println("target = " + target);
            System.out.println("pathParamPart = " + pathParamPart);
            System.out.println();
        }
        System.out.println("app.controllers.LoginController.(LoginController.java):1");
        System.out.println(o);

    }
}
